<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->
@section('content')
    <div class="x-nav">
    <span class="layui-breadcrumb mbx_fl_10">
        <a href="">首页</a>
        <a href="">库存单管理</a>
        <a><cite>出库订单列表</cite></a>
    </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="order_sn" placeholder="订单号" autocomplete="off"
                                       value="{{ Request()->get('order_sn') }}" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="tracking_number" placeholder="快递单号" autocomplete="off"
                                       value="{{ Request()->get('tracking_number') }}" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <select name="store_id" lay-filter="college" lay-search="">
                                    <option value="">选择商户</option>
                                    @foreach( $storeList as $kk => $item)
                                        <option value="{{$item['id']}}" @if(Request()->get('store_id') == $item['id']) selected @endif>{{$item['store_name']}}</option>
                                    @endforeach
                                </select>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="开始日" name="start_time"
                                       id="start" value="{{request()->input('start_time')}}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <input class="layui-input" autocomplete="off" placeholder="截止日" name="end_time" id="end"
                                       value="{{request()->input('end_time')}}">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                    <i class="layui-icon">&#xe615;</i>
                                </button>
                                <input type="hidden" id="export_excel" name="export_excel" value="0">
                                <button id="export_excel_btn" class="layui-btn" lay-submit="" lay-filter="sreach"><i
                                        class="layui-icon">&#xe65b;</i>导出Excel
                                </button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        <button class="layui-btn" onclick="xadmin.open('批量出库','/admin/stock/outOrderAdd')"><i
                                class="layui-icon"></i>批量出库
                        </button>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-table layui-form" style="width: 100%">
                            <thead>
                            <tr>
                                <th>出库单号</th>
                                <th>快递单号</th>
                                <th>出库状态</th>
                                <th>代理商</th>
                                <th>出库数量</th>
                                <th>操作人</th>
                                <th>出库备注</th>
                                <th>出库时间</th>
                                <th>出库商品批次</th>
                                <th>操作</th>
                            </thead>
                            <tbody>
                            @foreach($data as $item)
                                <tr>
                                    <td>
                                        {{$item['order_sn']}}
                                    </td>
                                    <td>
                                        {{$item['tracking_number']}}
                                    </td>
                                    <td>
                                        {{$item['status_name']}}
                                    </td>
                                    <td>
                                        {{$item['store_name']}}
                                    </td>
                                    <td>
                                        {{$item['total_number']}}
                                    </td>
                                    <td>
                                        {{$item['update_user']}}
                                    </td>
                                    <td>
                                        {{$item['remark']}}
                                    </td>
                                    <td>
                                        {{$item['created_at']}}
                                    </td>
                                    <td>
                                        {{$item['store_product_batch']}}
                                    </td>
                                    <td class="td-manage" style="min-width: 140px">
                                        <button class="layui-btn layui-btn layui-btn-xs"
                                                onclick="xadmin.open('查看','/admin/stock/outOrderEdit?id={{$item['id']}}',1100,630)">
                                            <i class="layui-icon">&#xe642;</i>查看
                                        </button>
                                        <a href="/admin/stock/orderPdf?id={{$item['id']}}">
                                            <button class="layui-btn layui-btn-primary" >
                                                <i class="icon iconfont">&#xe6c9;</i> 打印
                                            </button>
                                        </a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{ $data->links('admin/public/page') }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form', 'laydate'], function () {
            var form = layui.form;
            var laydate = layui.laydate;

            // 渲染表单
            form.render();

            // 监听select弹出，提升下拉层高度并调整卡片高度
            $(document).on('click', '.layui-form-select .layui-input', function () {
                // 判断是否是商户选择下拉
                var $selectWrap = $(this).closest('.layui-form-select');
                if($selectWrap.prev('select[name=\"store_id\"]').length > 0){
                    $selectWrap.find('dl').css({'max-height': '400px', 'overflow-y': 'auto'});
                    $selectWrap.closest('.layui-card').find('.layui-card-body').first().css('height', '200px');
                }
            });

            // 监听选中后还原高度
            $(document).on('click', '.layui-form-select dl dd', function () {
                var $select = $(this).closest('.layui-form-select');
                $select.find('dl').css({'max-height': '', 'overflow-y': ''});
                $select.closest('.layui-card').find('.layui-card-body').first().css('height', '');
            });

            // 鼠标移出下拉菜单时还原高度
            $(document).on('mouseleave', '.layui-form-select dl', function () {
                try {
                    var $select = $(this).closest('.layui-form-select');
                    $select.find('dl').css({'max-height': '', 'overflow-y': ''});
                    $select.closest('.layui-card').find('.layui-card-body').first().css('height', '');
                } catch(e) {
                    // 忽略异常
                }
            });

            // 日期渲染
            laydate.render({
                elem: '#start',
                type: 'datetime'
            });
            laydate.render({
                elem: '#end',
                type: 'datetime'
            });
        });

        // 删除
        function goods_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                //发异步删除数据
                $.ajax({
                    type: 'POST',
                    url: '/admin/goods/goodsDel',
                    data: {
                        id: id
                    },
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        if (data.code == 1) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除', {icon: 1, time: 2000});
                        } else {
                            layer.alert(data.msg, {icon: 7, time: 2000, closeBtn: false, btn: []});
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });
            });
        }

        // 分类展开收起的分类的逻辑
        $(function () {
            $("tbody.x-cate tr[fid!='0']").hide();
            // 栏目多级显示效果
            $('.x-show').click(function () {
                if ($(this).attr('status') == 'true') {
                    $(this).html('&#xe625;');
                    $(this).attr('status', 'false');
                    cateId = $(this).parents('tr').attr('cate-id');
                    $("tbody tr[fid=" + cateId + "]").show();
                } else {
                    cateIds = [];
                    $(this).html('&#xe623;');
                    $(this).attr('status', 'true');
                    cateId = $(this).parents('tr').attr('cate-id');
                    getCateId(cateId);
                    for (var i in cateIds) {
                        $("tbody tr[cate-id=" + cateIds[i] + "]").hide().find('.x-show').html('&#xe623;').attr('status', 'true');
                    }
                }
            })
        })

        var cateIds = [];

        function getCateId(cateId) {
            $("tbody tr[fid=" + cateId + "]").each(function (index, el) {
                id = $(el).attr('cate-id');
                cateIds.push(id);
                getCateId(id);
            });
        }

        $("#export_excel_btn").on('click', function () {
            layer.load(2, {
                time: 10000
            });
            $("#export_excel").val(1)
        });
        $("#search").on('click', function () {
            layer.load(2, {
                time: 10000
            });
            $("#export_excel").val(0);
        });
    </script>
@endsection

<style>
.layui-form-select dl {
    max-height: 400px !important;
    overflow-y: auto !important;
}
</style>
